<!--<!DOCTYPE html>-->
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>注册云信id</title>
</head>
<!--<script type="text/javascript" src="../js/jquery-3.1.0.min.js">
</script>-->
<script>

//以post方式发送数据为例
function chuFa() { //html元素事件触发的函数
    var myXMLHttpRequest = null;
    if (window.ActiveXObject) {
        myXMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        myXMLHttpRequest = new XMLHttpRequest();
    }
    var url = "http://localhost:8080/createAccid.do";
    var callerAcc=document.getElementById("accid").value;
   // var caller=document.getElementById("caller").value;
   // var callee=document.getElementById("callee").value;
    var postData = {
        "accid": callerAcc
       // "caller": caller,
       // "callee":callee
    };

    postData = (function(obj){ // 转成post需要的字符串.
        var str = "";

        for(var prop in obj){
            str += prop + "=" + obj[prop] + "&"
        }
        return str;
    })(postData);

    //var data = "callerAcc=callerAcc";
    myXMLHttpRequest.open("post", url, true);
    myXMLHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    myXMLHttpRequest.send(postData);
    myXMLHttpRequest.onreadystatechange = function(){
        if (myXMLHttpRequest.readyState == 4) {
            if(myXMLHttpRequest.status == 200){
                var res = myXMLHttpRequest.responseText;
                var jsonObj = eval("("+res+")");
                //接下来就可以使用jsonObj这个json对象取出其中的属性值，做一些修改html元素value值等操作了。
                var code=jsonObj["code"];
                if(code==200){
                    alert(jsonObj["code"]);
                }else{
                    alert(jsonObj["desc"]);
                }
                //alert(jsonObj["code"]);
                //alert(jsonObj["obj"]["session"]);
            }else{
                alert("失败。。。");
            }

        }
    }

}
</script>
<body>
  <div>

     <h1>创建云信id</h1>
      accid: <input type="text" name="accid" id="accid">
      <br>
      <hr>
<input type="button" id="call" onclick="chuFa()" value="创建云信id">

  </div>
</body>
</html>